package org.example.translate_braille.controller;


import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiOperation;
import org.example.translate_braille.entity.User;
import org.example.translate_braille.resdata.X;
import org.example.translate_braille.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Jacky
 * @since
 */
@RestController
@RequestMapping("/translate_braille/user")
public class UserController {
    @Autowired
    UserService userService;

    @PostMapping("/showUserList")
    @ApiOperation(value="列表+查询")
    public X<User> showUserList(@RequestBody User user){
        return userService.showUserList(user);
    }

    @PostMapping("/inOrUpUser")
    @ApiOperation(value="新增+更新")
    public X<User> inOrUpUser(@RequestBody JSONObject jsonObject){
        User user = new User();
        user.setId(jsonObject.getString("id"));
        user.setUserName(jsonObject.getString("nickname"));
        user.setUserImg(jsonObject.getString("img"));
        user.setOpenId(jsonObject.getString("openid"));
        user.setUserPassword(jsonObject.getString("password"));
        return userService.inOrUpUser(user);
    }

    @PostMapping("/deleteUser")
    @ApiOperation(value="删除+批量删除")
    public X<User> deleteUser(@RequestBody User user){
        return userService.deleteUser(user);
    }
}

